<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\abnormalorder\model;

class OrderWander extends \app\BaseModel
{
    protected $name = "massage_service_abnormal_order_wander";
    protected $append = ["role"];
    public function getRoleAttr($value, $data)
    {
        if(!empty($data["id"]) && !empty($data["process_id"])) {
            $role_model = new OrderRole();
            $dis = ["a.process_id" => $data["process_id"], "a.wander_id" => $data["id"]];
            $list2 = $role_model->alias("a")->join("shequshop_school_admin b", "a.user_id = b.id AND b.status =1", "left")->where($dis)->where("a.type", "in", [2, 3])->field("a.*,b.agent_name as user_name")->group("a.id")->select()->toArray();
            if(!empty($list2)) {
                foreach ($list2 as &$s) {
                    if($s["type"] == 3) {
                        $s["user_name"] = "代理商";
                    }
                }
            }
            return $list2;
        }
    }
    public function dataAdd($data)
    {
        $res = $this->insert($data);
        return $res;
    }
    public function wanderAdd($insert, $uniacid, $process_id)
    {
        $role_model = new OrderRole();
        $this->where(["process_id" => $process_id])->delete();
        if(!empty($insert)) {
            foreach ($insert as $value) {
                $wander_insert = ["uniacid" => $uniacid, "process_id" => $process_id, "pass_type" => $value["pass_type"], "deduct_status" => $value["deduct_status"], "status" => $value["status"]];
                $this->dataAdd($wander_insert);
                $wander_id = $this->getLastInsID();
                $role_insert = [];
                foreach ($value["role"] as $ks => $vs) {
                    $role_insert[$ks] = ["uniacid" => $uniacid, "process_id" => $process_id, "type" => $vs["type"], "user_id" => $vs["user_id"], "pass_type" => $value["pass_type"], "wander_id" => $wander_id];
                }
                $role_model->saveAll($role_insert);
            }
        }
        return true;
    }
    public function dataUpdate($dis, $data)
    {
        $res = $this->where($dis)->update($data);
        return $res;
    }
    public function dataList($dis, $page)
    {
        $data = $this->where($dis)->order("id desc")->paginate($page)->toArray();
        return $data;
    }
    public function dataInfo($dis)
    {
        $data = $this->where($dis)->find();
        return !empty($data) ? $data->toArray() : [];
    }
}

?>